<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>计时器</title>
  <script>
    var hour,minute,second;//时 分 秒
    hour=minute=second=0;//初始化
    var millisecond=0;//毫秒
    var int;
    function reset()//重置
    {
      window.clearInterval(int);
      millisecond=hour=minute=second=0;
      document.getElementById('timetext').value='00时00分00秒';
    }
  
    function start()//开始
    {
      int=setInterval(timer,50);
    }
  
    function timer()//计时
    {
      millisecond=millisecond+50;
      if(millisecond>=1000)
      {
        millisecond=0;
        second=second+1;
      }
      if(second>=60)
      {
        second=0;
        minute=minute+1;
      }
  
      if(minute>=60)
      {
        minute=0;
        hour=hour+1;
      }
      document.getElementById('timetext').value=hour+'时'+minute+'分'+second+'秒'+millisecond+'毫秒';
  
    }
  
    function stop()//暂停
    {
      window.clearInterval(int);
    }
    
    function count() {
        var str = document.getElementById('timetext');
        timetext.innerHTML = timetext.innerHTML + '<div>' + str +'</div>';

    }

  </script>
</head>
<body>
<div style="text-align: center">
  <input type="text" id="timetext" value="00时00分00秒" readonly><br>
  <button type="button" onclick="start()">开始</button> 
  <button type="button" onclick="stop()">暂停</button> 
  <button type="button" onclick="count()">计次</button>
  <button type="button" onclick="reset()">重置</button>
</div>
</body>
</html>